﻿
// **************************************************************************
//    Class Created by Mick Doherty (Dotnetrix) Feb 2010
//    http://dotnetrix.co.uk/
//
//    ...for GlassUI (an AeroGlass UI Library)
//    http://glassui.codeplex.com/
// **************************************************************************

using System;
using System.ComponentModel;
using System.Reflection;
using System.Resources;
using GlassUI.Properties;

namespace GlassUI.Design
{
    [AttributeUsage(AttributeTargets.All)]
    internal sealed class GlassUIDescriptionAttribute : DescriptionAttribute
    {
        public GlassUIDescriptionAttribute(string description)
            : base(description)
        {
        }

        public GlassUIDescriptionAttribute(string description, string libraryName)
            : base(description)
        {
            this.usingExternalLibrary = true;
            this.externalLibraryFile = libraryName;
        }

        private bool usingExternalLibrary;
        private string externalLibraryFile;

        public override string Description
        {
            get
            {
                if (!usingExternalLibrary)
                    return Resources.ResourceManager.GetString(this.DescriptionValue);
                else
                {
                    String path = System.IO.Path.Combine(System.Runtime.InteropServices.RuntimeEnvironment.GetRuntimeDirectory(), externalLibraryFile + ".dll");
                    Assembly assy = Assembly.LoadFrom(path);

                    ResourceManager rm = new ResourceManager(externalLibraryFile, assy);

                    return rm.GetString(this.DescriptionValue);
                }
            }
        }

    }


}
